import { defHttp } from '/@/common/util/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/emp/hubTeamQuotaOrg/getPage',
  save = '/emp/hubTeamQuotaOrg/add',
  edit = '/emp/hubTeamQuotaOrg/edit',
  deleteOne = '/emp/hubTeamQuotaOrg/delete',
  updateBatch = '/emp/hubTeamQuotaOrg/updateBatch',
  deleteBatch = '/emp/hubTeamQuotaOrg/deleteBatch',
  importExcel = '/emp/hubTeamQuotaOrg/importExcel',
  exportXls = '/emp/hubTeamQuotaOrg/exportXls',
  getQuotaList = '/emp/hubTeamQuota/getList', //获取基础定额影响因子集合
  init = '/emp/hubTeamQuotaOrg/init', // 初始化
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量更新
 * @param params
 */
export const updateBatch = (params) => {
  const url = Api.updateBatch;
  return defHttp.post({ url: url, params });
};
/**
 * 批量删除
 * @param params
 */
export const deleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
}


/**
 * 获取基础定额影响因子集合-getFactorList
 * @param params
 */
export const getQuotaList = () => defHttp.get({ url: Api.getQuotaList });

/**
 * 
 * @param params 初始化
 * @returns 
 */
export const init = (params) => defHttp.post({ url: Api.init, params });